/*
 * @lc app=leetcode.cn id=720 lang=javascript
 *
 * [720] 词典中最长的单词
 */

// @lc code=start
/**
 * @param {string[]} words
 * @return {string}
 */
var longestWord = function (words) {
    let max_len=0
    let init_arr=words.filter((item)=>{
        max_len=Math.max(max_len,item.length)
        return item.length==1
    })
    let init=2
    let flit=function(item){
        for(let i of init_arr){
            if(item.includes(i))return true
        }
        return false 
    }
    while(init<=max_len){
       
        let res=words.filter((item)=>{
            return item.length==init&&(
                flit(item)
            )
        })
        if(res.length==0)break
        init_arr=res
        console.log(res)
        init++
    }
    return init_arr.sort()[0]
};
// @lc code=end

longestWord(["yo", "ew", "fc", "zrc", "yodn", "fcm", "qm", "qmo", "fcmz", "z", "ewq", "yod", "ewqz", "y"])